package com.itcodai.controller.course02;

import com.itcodai.entity.User;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author c-fanqj
 * @date 2021/12/17
 * @apiNote Spring Boot 中默认使用的 json 解析框架是 jackson
 */
//@RestController
//@RequestMapping("/json")
public class JsonController {

    //@RequestMapping("/user")
    public User getUser() {
        return new User(1L, "jiejie", "1234567890");
    }

    //@RequestMapping("/list")
    public List<User> getUserList() {
        List<User> userList = new ArrayList<>();
        User user1 = new User(1L, "jiejie", "123456");
        User user2 = new User(2L, "haha", "12345678");
        userList.add(user1);
        userList.add(user2);
        return userList;
    }

    // {"作者信息":{"id":1,"username":"jiejie","password":""},"CSDN地址":"",
    // "粉丝数量":4153,"博客地址":"http://1234.com"}
    //@RequestMapping("/map")
    public Map<String, Object> getMap() {
        Map<String, Object> map = new HashMap<>(3);
        User user = new User(1L, "jiejie", null);
        map.put("作者信息", user);
        map.put("博客地址", "http://1234.com");
        map.put("CSDN地址", null);
        map.put("粉丝数量", 4153);
        return map;
    }

}
